package BookStore.dao;

import BookStore.model.Admin;
import BookStore.util.DbUtil_1;
import BookStore.view.LoginFrame;

import javax.swing.*;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class AdminDao {
    String name_1;
    String pswd_1;
    public AdminDao(Admin admin) {
        name_1 = admin.getAdminName();
        pswd_1 = admin.getAdminPsw();
    }
    public void register_1() throws Exception {
        Connection con_1 = DbUtil_1.getCon_1();
        Statement statement_1 = con_1.createStatement();
        String sql3 = "select * from admin where name = '" + name_1 + "' ";
        ResultSet result_1 = statement_1.executeQuery(sql3);
        if (result_1.next()) {
            JOptionPane.showMessageDialog(null, "该管理员已存在");
        } else {
            String sql4 = "insert into admin (name ,psw) values ('" + name_1 + "','" + pswd_1 + "')";
            statement_1.executeUpdate(sql4);
            JOptionPane.showMessageDialog(null, "管理员注册成功");
            new LoginFrame().setVisible(true);
        }
        con_1.close();
        statement_1.close();
    }
}

